package io.renren.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.stereotype.Controller;

import io.renren.entity.Test;
import io.renren.service.TestService;


import io.renren.entity.SysRoleEntity;
import io.renren.service.SysRoleService;	
import io.renren.utils.PageUtils;
import io.renren.utils.R;


/**
 * 员工表
 * 
 * @author zk
 * @email zk13899@163.com
 * @date 2017-07-13 08:29:42
 */
@Controller
@RequestMapping("test")
public class CarTestController {
	@Autowired
	private TestService testService;
		@Autowired
	private SysRoleService sysRoleService;
	
	@RequestMapping("/test.html")
	public String list(){
		return "test/test.html";
	}
	
	/**
	 * 列表
	 */
	@ResponseBody
	@RequestMapping("/list")
	@RequiresPermissions("test:list")
	public R list(Integer page, Integer limit,Integer idRole){
		Map<String, Object> map = new HashMap<>();
				map.put("idRole",idRole);
				map.put("offset", (page - 1) * limit);
		map.put("limit", limit);
		
		//查询列表数据
		List<Test> testList = testService.queryList(map);
		int total = testService.queryTotal(map);
		
		PageUtils pageUtil = new PageUtils(testList, total, limit, page);
		
		return R.ok().put("page", pageUtil);
	}
	
		
	/* 关联列表 */
	@ResponseBody
	@RequestMapping("/sysRole/list")

	public R sysRoleList() {
		Map<String, Object> map = new HashMap<>();
		List<SysRoleEntity> listSysRole = sysRoleService.queryList(map);

		return R.ok().put("listSysRole", listSysRole);
	}
	
	
		/**
	 * 信息
	 */
	@ResponseBody
	@RequestMapping("/info/{id}")
	@RequiresPermissions("test:info")
	public R info(@PathVariable("id") Long id){
		Test test = testService.queryObject(id);
		
		return R.ok().put("test", test);
	}
	
	/**
	 * 保存
	 */
	@ResponseBody
	@RequestMapping("/save")
	@RequiresPermissions("test:save")
	public R save(@RequestBody Test test){
		testService.save(test);
		
		return R.ok();
	}
	
	/**
	 * 修改
	 */
	@ResponseBody
	@RequestMapping("/update")
	@RequiresPermissions("test:update")
	public R update(@RequestBody Test test){
		testService.update(test);
		
		return R.ok();
	}
	
	/**
	 * 删除
	 */
	@ResponseBody
	@RequestMapping("/delete")
	@RequiresPermissions("test:delete")
	public R delete(@RequestBody Long[] ids){
		testService.deleteBatch(ids);
		
		return R.ok();
	}
	
}
